﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common;
using System.Data.SqlClient;
using System.Data;

namespace DAL
{
    public class PassportInfo
    {
        public static Boolean InsertInfo(PassportInfoData p)
        {
            PassportManageDataSetTableAdapters.PassportInfoTableAdapter pm = new PassportManageDataSetTableAdapters.PassportInfoTableAdapter();
            int ret=pm.InsertQuery(p.TaskCode, p.CardCode, p.Birthday, p.CardID, p.Name, p.OprationNumber, p.Pillar, p.Layer, p.Cell, p.AddTime, p.Operator);
//             string sql = @"INSERT INTO PassportInfo " +
//                             "(TaskCode, CardCode, Birthday,CardID, Name,OprationNumber,Operator,AddTime,Pillar,Layer,Cell)" +
//                             "VALUES (@taskCode, @cardCode, @birthday,@idCard, @name,@OprationNumber,@Operator,@AddTime,@Pillar,@Layer,@Cell)";
//             SqlParameter taskCode = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@taskCode", SqlDbType.VarChar, p.TaskCode);
//             SqlParameter cardCode = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@cardCode", SqlDbType.VarChar, p.CardCode);
//             SqlParameter birthday = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@birthday", SqlDbType.SmallDateTime, p.Birthday);
//             SqlParameter idCard = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@idCard", SqlDbType.VarChar, p.CardID);
//             SqlParameter name = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@name", SqlDbType.NVarChar, p.Name);
//             SqlParameter OprationNumber = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@OprationNumber", SqlDbType.NVarChar, p.OprationNumber);
//             SqlParameter Operator = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@Operator", SqlDbType.NVarChar, p.Operator);
//             SqlParameter AddTime = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@AddTime", SqlDbType.DateTime, p.AddTime);
//             SqlParameter Pillar = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@Addr", SqlDbType.Int, p.Pillar);
//             SqlParameter Layer = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@Addr", SqlDbType.Int, p.Layer);
//             SqlParameter Cell = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@Addr", SqlDbType.Int, p.Cell);
//             int ret = WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql, taskCode, cardCode, birthday, idCard, name, OprationNumber, Operator, AddTime, Pillar, Layer, Cell);
            if (ret == 0)
                return false;
            else
                return true;
        }
        public static PassportInfoData GetInfoByTaskCode(string TaskCode)
        {
            PassportManageDataSetTableAdapters.PassportInfoTableAdapter pm = new PassportManageDataSetTableAdapters.PassportInfoTableAdapter();
            DataTable dt = pm.GetDataByTaskCode(TaskCode);
//             PassportInfoData p=new PassportInfoData();
//             DataRow dr=dt.Rows[0];
//             p.TaskCode = dt.Rows[0][0];
//             string sql = string.Format("SELECT * FROM PassportInfo WHERE (TaskCode = '{0}')",
//                                     TaskCode);
//             IDataReader reader = WFNetLib.ADO.SQLServerOP.ReaderExecuteSQL(sql);
//             PassportInfoData p = null;
//             if (reader.Read())
//             {                
//                 p = PassportInfoDataFactory.Construct(reader);
//             }
//             reader.Close();
            return Common.PassportInfoDataFactory.Construct(dt);
        }
        public static bool DeleteInfoByTaskCode(string TaskCode)
        {
            PassportManageDataSetTableAdapters.PassportInfoTableAdapter pm = new PassportManageDataSetTableAdapters.PassportInfoTableAdapter();
            int ret = pm.DeleteByTaskCode(TaskCode);
//             string sql = string.Format("DELETE FROM PassportInfo WHERE (TaskCode = '{0}')",
//                                     TaskCode);
//             int ret= WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql);
            if (ret == 0)
                return false;
            else
                return true;
        }
        public static DataTable GetInfosByPosition(int Pillar, int Layer, int Cell)
        {
//             string sql = string.Format("SELECT * FROM PassportInfo WHERE (Pillar={0} AND Layer={1} AND Cell={2})",
//                                     Pillar,Layer,Cell);
//             DataTable dt = WFNetLib.ADO.SQLServerOP.DataTableSQL(sql);
            PassportManageDataSetTableAdapters.PassportInfoTableAdapter pm = new PassportManageDataSetTableAdapters.PassportInfoTableAdapter();
            return pm.GetDataByPosition(Pillar,Layer,Cell);
        }
        public static DataTable GetInfosByLayer(int Pillar, int Layer)
        {
//             string sql = string.Format("SELECT * FROM PassportInfo WHERE (Pillar={0} AND Layer={1} )",
//                                     Pillar, Layer);
//             DataTable dt = WFNetLib.ADO.SQLServerOP.DataTableSQL(sql);
//             return dt;
            PassportManageDataSetTableAdapters.PassportInfoTableAdapter pm = new PassportManageDataSetTableAdapters.PassportInfoTableAdapter();
            return pm.GetDataByLayer(Pillar, Layer);
        }
        public static DataTable GetInfosByPillar(int Pillar)
        {
//             string sql = string.Format("SELECT * FROM PassportInfo WHERE (Pillar={0})",
//                                     Pillar);
//             DataTable dt = WFNetLib.ADO.SQLServerOP.DataTableSQL(sql);           
//             return dt;
            PassportManageDataSetTableAdapters.PassportInfoTableAdapter pm = new PassportManageDataSetTableAdapters.PassportInfoTableAdapter();
            return pm.GetDataByPillar(Pillar);
        }
        public static DataTable GetInfosByTaskCode(string taskCode)
        {
//             string sql = string.Format("SELECT * FROM PassportInfo WHERE (TaskCode LIKE '%{0}%')",
//                                     taskCode);
//             DataTable dt = WFNetLib.ADO.SQLServerOP.DataTableSQL(sql);
//             return dt;
            PassportManageDataSetTableAdapters.PassportInfoTableAdapter pm = new PassportManageDataSetTableAdapters.PassportInfoTableAdapter();
            return pm.GetDataByLikeTaskCode(taskCode);
        }
        public static DataTable GetInfosByName(string name)
        {
//             string sql = string.Format("SELECT * FROM PassportInfo WHERE (Name LIKE '%{0}%')",
//                                     name);
//             DataTable dt = WFNetLib.ADO.SQLServerOP.DataTableSQL(sql);
//             return dt;
            PassportManageDataSetTableAdapters.PassportInfoTableAdapter pm = new PassportManageDataSetTableAdapters.PassportInfoTableAdapter();
            return pm.GetDataByName(name);
        }
        public static DataTable GetInfosByCardID(string CardID)
        {
//             string sql = string.Format("SELECT * FROM PassportInfo WHERE (CardID LIKE '%{0}%')",
//                                     CardID);
//             DataTable dt = WFNetLib.ADO.SQLServerOP.DataTableSQL(sql);
//             return dt;
            PassportManageDataSetTableAdapters.PassportInfoTableAdapter pm = new PassportManageDataSetTableAdapters.PassportInfoTableAdapter();
            return pm.GetDataByCardID(CardID);
        }
        public static DataTable GetInfosByCardCode(string CardCode)
        {
//             string sql = string.Format("SELECT * FROM PassportInfo WHERE (CardCode LIKE '%{0}%')",
//                                     CardCode);
//             DataTable dt = WFNetLib.ADO.SQLServerOP.DataTableSQL(sql);
//             return dt;
            PassportManageDataSetTableAdapters.PassportInfoTableAdapter pm = new PassportManageDataSetTableAdapters.PassportInfoTableAdapter();
            return pm.GetDataByCardCode(CardCode);
        }
        public static DataTable GetInfosByOprationNumber(string OprationNumber)
        {
//             string sql = string.Format("SELECT * FROM PassportInfo WHERE (OprationNumber LIKE '%{0}%')",
//                                     OprationNumber);
//             DataTable dt = WFNetLib.ADO.SQLServerOP.DataTableSQL(sql);
//             return dt;
            PassportManageDataSetTableAdapters.PassportInfoTableAdapter pm = new PassportManageDataSetTableAdapters.PassportInfoTableAdapter();
            return pm.GetDataByOprationNumber(OprationNumber);
        }
        public static bool UpdateInfo(PassportInfoData p)
        {
//             string sql = @"UPDATE PassportInfo SET" +
//                             "cardCode=@cardCode" + "," +
//                             "birthday=@birthday" + "," +
//                             "CardID=@idCard" + "," +
//                             "name=@name" + "," +
//                             "OprationNumber=@OprationNumber" + "," +
//                             "Operator=@Operator" + "," +
//                             "AddTime=@AddTime" + "," +
//                             "Pillar=@Pillar" + "," +
//                             "Layer=@Layer" + "," +
//                             "Cell=@Cell" +
//                             "WHERE taskCode='@taskCode'";
//             SqlParameter taskCode = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@taskCode", SqlDbType.VarChar, p.TaskCode);
//             SqlParameter cardCode = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@cardCode", SqlDbType.VarChar, p.CardCode);
//             SqlParameter birthday = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@birthday", SqlDbType.SmallDateTime, p.Birthday);
//             SqlParameter idCard = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@idCard", SqlDbType.VarChar, p.CardID);
//             SqlParameter name = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@name", SqlDbType.NVarChar, p.Name);
//             SqlParameter OprationNumber = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@OprationNumber", SqlDbType.NVarChar, p.OprationNumber);
//             SqlParameter Operator = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@Operator", SqlDbType.NVarChar, p.Operator);
//             SqlParameter AddTime = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@AddTime", SqlDbType.DateTime, p.AddTime);
//             SqlParameter Pillar = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@Addr", SqlDbType.Int, p.Pillar);
//             SqlParameter Layer = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@Addr", SqlDbType.Int, p.Layer);
//             SqlParameter Cell = WFNetLib.ADO.SQLServerOP.CreateSqlParam("@Addr", SqlDbType.Int, p.Cell);
//             int ret = WFNetLib.ADO.SQLServerOP.NonQuerySQL(sql, taskCode, cardCode, birthday, idCard, name, OprationNumber, Operator, AddTime, Pillar, Layer, Cell);
            PassportManageDataSetTableAdapters.PassportInfoTableAdapter pm = new PassportManageDataSetTableAdapters.PassportInfoTableAdapter();
            int ret = pm.UpdateQuery(p.CardCode, p.Birthday, p.CardID, p.Name, p.OprationNumber, p.Pillar, p.Layer, p.Cell, p.AddTime, p.Operator,p.TaskCode);
            if (ret == 0)
                return false;
            else
                return true;
        }
    }
}
